#include "simpletcpsocketdll.h"
#include "simpletcpsocketdll_global.h"

static SimpleTcpSocketDLL* pSimpleTcpSocketInstance = nullptr;

bool COM_InstanceExist(){
    if(pSimpleTcpSocketInstance == nullptr) return false;
    else                                    return true;
}

short COM_ComInstanceInit(){
    if(pSimpleTcpSocketInstance == nullptr){
        pSimpleTcpSocketInstance = new SimpleTcpSocketDLL();
    }
    return 0;
}

short COM_ComInstanceRelease(){
    if(pSimpleTcpSocketInstance != nullptr){
        delete pSimpleTcpSocketInstance;
        return 1;
    }
    return 0;
}

void COM_clientMainThreadLoopRun(short type){
    if(pSimpleTcpSocketInstance != nullptr){
        if(pSimpleTcpSocketInstance != nullptr){
            pSimpleTcpSocketInstance->SimpleclientMainThreadLoopRun(type);
        }
    }
}

short COM_addTcpClient(const QString ip,const int port,int &Order){
    if(pSimpleTcpSocketInstance != nullptr){
        if(pSimpleTcpSocketInstance != nullptr){
            return pSimpleTcpSocketInstance->SimpleTcpClientadd(ip,port,Order);
        }
    }
    return 0;
}

short COM_removeTcpClient(const int Order){
    if(pSimpleTcpSocketInstance != nullptr){
        if(pSimpleTcpSocketInstance != nullptr){
            return pSimpleTcpSocketInstance->SimpleTcpClientremove(Order);
        }
    }
    return 0;
}

short COM_connectToServer(const int Order){
    if(pSimpleTcpSocketInstance != nullptr){
        if(pSimpleTcpSocketInstance != nullptr){
            return pSimpleTcpSocketInstance->SimpleTcpClientconnect(Order);
        }
    }
    return 0;
}

short COM_disConnectToServer(const int Order){
    if(pSimpleTcpSocketInstance != nullptr){
        return pSimpleTcpSocketInstance->SimpleTcpClientDisconnect(Order);
    }
    return 0;
}

short COM_clientSendData(const int Order,QByteArray Data){
    if(pSimpleTcpSocketInstance != nullptr){
        if(pSimpleTcpSocketInstance != nullptr){
            return pSimpleTcpSocketInstance->SimpleTcpClientWriteData(Order,Data);
        }
    }
    return 0;
}

short COM_clientReadData(const int Order,QByteArray& Data){
    if(pSimpleTcpSocketInstance != nullptr){
        if(pSimpleTcpSocketInstance != nullptr){
            return pSimpleTcpSocketInstance->SimpleTcpClientReadData(Order,Data);
        }
    }
    return 0;
}

bool COM_getClientReadStatus(const int Order){
    bool status;
    if(pSimpleTcpSocketInstance != nullptr){
        if(pSimpleTcpSocketInstance != nullptr){
            pSimpleTcpSocketInstance->SimpleTcpClientRead2Read(Order,status);
            return status;
        }
    }
    return 0;
}

bool COM_getClientSendStatus(const int Order){
    bool status;
    if(pSimpleTcpSocketInstance != nullptr){
        if(pSimpleTcpSocketInstance != nullptr){
            pSimpleTcpSocketInstance->SimpleTcpClientSendBusy(Order,status);
            return status;
        }
    }
    return 0;
}

bool COM_getClientConnectStatus(const int Order){
    bool status;
    if(pSimpleTcpSocketInstance != nullptr){
        if(pSimpleTcpSocketInstance != nullptr){
            status = pSimpleTcpSocketInstance->isTcpClientConnectStatus(Order);
            return status;
        }
    }
    return 0;
}
